import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:speed_app/common/index.dart';
import 'index.dart';

/// 手机号登录
class LoginPage extends GetView<LoginController> {
  const LoginPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView(BuildContext context) {
    return ListView(
      shrinkWrap: true,
      // 禁止回弹(ClampingScrollPhysics)和滚动
      physics: const NeverScrollableScrollPhysics(),
      children: [
        // 忘记密码
        <Widget>[
          const SizedBox().expanded(),
          Container(
            height: 50,
            width: 80,
            alignment: Alignment.centerRight,
            child: const Text(
              '忘记密码',
              style: TextStyle(
                fontSize: 15,
                fontWeight: FontWeight.bold,
              ),
            ),
          ).withOnTap(() => controller.onForgetPassword()),
        ].toRow(),
        const Padding(
          padding: EdgeInsets.only(top: 30),
          child: Text(
            '同城速约，欢迎您！',
            style: TextStyle(
              fontSize: 20,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        const Padding(
          padding: EdgeInsets.only(top: 20),
          child: Text(
            '同城/出差/旅行交友平台，100%真人交友',
            style: TextStyle(
              fontSize: 15,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.only(top: 60),
          child: LoginInputWidget(
            title: '手机号码',
            keyboardType: TextInputType.phone,
            inputController: controller.phoneController,
            leftWidget: <Widget>[
              Container(
                width: 60,
                alignment: Alignment.center,
                child: const Text('+ 86'),
              ),
              Container(
                width: 1,
                height: 20,
                color: Colors.black38,
              ),
            ].toRow(),
          ),
        ),
        Padding(
          padding: const EdgeInsets.only(top: 30),
          child: Obx(() => LoginInputWidget(
            title: '密码',
            leftWidget: const SizedBox(width: 10,),
            obscureText: controller.isSecrecy.value,
            inputController: controller.passwordController,
            rightWidget: Container(
              margin: const EdgeInsets.only(right: 10),
              width: 50,
              child: IconWidget.image(
                controller.isSecrecy.value ? AssetsImages.textDisplayPng:AssetsImages.textShowPng,
                size: 20,
              ),
            ).withOnTap(() {
              controller.isSecrecy.value = !controller.isSecrecy.value;
              //点击是否明文展示
              print('==是否明文展示:${controller.isSecrecy.value}==');
            }),
          )),
        ),

        ButtonWidget.primary(
          "注册/登录",
          borderRadius: 50,
          backgroundColor: Colors.black,
          onTap:()=> controller.onLogin(),
        ).paddingOnly(top: 40),

        const SizedBox(height: 20,),
        // 协议
        <Widget>[
          InkWell(
            highlightColor: Colors.transparent,
            radius: 0,
            onTap: (){
              controller.isAgree.value = !controller.isAgree.value;
            },
            child: Container(
              height: 30,
              width: 30,
              margin: const EdgeInsets.only(right: 2),
              alignment: Alignment.center,
              child: Obx(() => IconWidget.image(
                controller.isAgree.value ? AssetsImages.selectedPng : AssetsImages.unselectedPng,
                size: 20,
              )),
            ),
          ),
          // 富文本
          Text.rich(
            textAlign: TextAlign.center,
            TextSpan(
                children: [
                  const TextSpan(
                      text: "同意同城速约",
                      style: TextStyle(fontSize: 14,color: Colors.grey)
                  ),
                  TextSpan(
                      text: "《用户协议》",
                      style: const TextStyle(fontSize: 14,color: Colors.greenAccent),
                      recognizer: TapGestureRecognizer()
                        ..onTap = (){
                          Loading.toast("查看用户协议");
                        }
                  ),
                  const TextSpan(
                      text: "以及",
                      style: TextStyle(fontSize: 14, color: Colors.grey)
                  ),
                  TextSpan(
                      text: "《隐私政策》",
                      style: const TextStyle(fontSize: 13,color: Colors.greenAccent),
                      recognizer: TapGestureRecognizer()
                        ..onTap = (){
                          Loading.toast("查看隐私政策");
                        }
                  ),
                ]
            ),
          ),
        ].toRow(),

      ],
    ).paddingAll(AppSpace.page);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LoginController>(
      init: LoginController(),
      id: "login",
      builder: (_) {
        return Scaffold(
          resizeToAvoidBottomInset: false,
          body: SafeArea(
            child: _buildView(context),
          ),
        );
      },
    );
  }
}
